class AccountBudgetRulesController < ApplicationController
  # GET /account_budget_rules
  # GET /account_budget_rules.json
  def index

    a= params[:account_id]


     @account_budget_rules = {:categories => AccountBudgetRule.find_by_sql("select name as category, budget_limit, ifnull(utilization,0) as utilization from account_budget_rules where account_id='" + a  +"'")}

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @account_budget_rules }
    end
  end

  # GET /account_budget_rules/1
  # GET /account_budget_rules/1.json
  def show
    @account_budget_rule = AccountBudgetRule.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @account_budget_rule }
    end
  end

  # GET /account_budget_rules/new
  # GET /account_budget_rules/new.json
  def new
    @account_budget_rule = AccountBudgetRule.new

    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @account_budget_rule }
    end
  end

  # GET /account_budget_rules/1/edit
  def edit
    @account_budget_rule = AccountBudgetRule.find(params[:id])
  end

  # POST /account_budget_rules
  # POST /account_budget_rules.json
  def create
    @account_budget_rule = AccountBudgetRule.new(params[:account_budget_rule])

    respond_to do |format|
      if @account_budget_rule.save
        format.html { redirect_to @account_budget_rule, notice: 'Account budget rule was successfully created.' }
        format.json { render json: @account_budget_rule, status: :created, location: @account_budget_rule }
      else
        format.html { render action: "new" }
        format.json { render json: @account_budget_rule.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /account_budget_rules/1
  # PUT /account_budget_rules/1.json
  def update
    @account_budget_rule = AccountBudgetRule.find(params[:id])

    respond_to do |format|
      if @account_budget_rule.update_attributes(params[:account_budget_rule])
        format.html { redirect_to @account_budget_rule, notice: 'Account budget rule was successfully updated.' }
        format.json { head :ok }
      else
        format.html { render action: "edit" }
        format.json { render json: @account_budget_rule.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /account_budget_rules/1
  # DELETE /account_budget_rules/1.json
  def destroy
    @account_budget_rule = AccountBudgetRule.find(params[:id])
    @account_budget_rule.destroy

    respond_to do |format|
      format.html { redirect_to account_budget_rules_url }
      format.json { head :ok }
    end
  end
end
